﻿using CPPEI.Net;
using CPPEI.ShareScreen.Contract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.ShareScreen.Server.Handler
{
    public class GetClientListHandler : BaseRequestHandler<ReqGetClientListData, RespGetClientListData>
    {
        protected override RespGetClientListData OnHandle(NetServerData serverData, NetClientProxy requestClient, NetPackage request, ReqGetClientListData requestData)
        {
            RespGetClientListData responseData = new RespGetClientListData();
            responseData.IdArr = new uint[serverData.ClientCount];
            responseData.IPArr = new UInt32[serverData.ClientCount];
            responseData.PortArr = new int[serverData.ClientCount];
            int clientIndex = 0;
            for (uint index = 0; index < serverData.ClientList.Length; index++)
            {
                if (serverData.ClientList[index] != null)
                {
                    responseData.IdArr[clientIndex] = serverData.ClientList[index].Id;
                    responseData.IPArr[clientIndex] = serverData.ClientList[index].IP;
                    responseData.PortArr[clientIndex] = serverData.ClientList[index].Port;
                    clientIndex++;
                }
            }
            return responseData;
        }
    }
}
